package fmi.events;

import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;

public class EventDispatcher<E extends EventObject, L extends CommonEventListener<E>> {
	private List<L> listeners;
	
	public EventDispatcher() {
		listeners = new ArrayList<L>();
	}
	
	public synchronized void addEventListener(L listener) {
		listeners.add(listener);
	}
	
	public synchronized void removeEventListener(L listener) {
		listeners.remove(listener);
	}
	
	public synchronized void dispatchEvent(E event) {
		for (L listener : listeners) {
			listener.handleEvent(event);
		}
	}
}
